<!DOCTYPE html>
<html>
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>传智健康</title>
    <meta name="description" content="传智健康">
    <meta name="keywords" content="传智健康">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">

    <style type="text/css">
    .el-main{
        position: absolute;
        top: 70px;
        bottom: 0px;
        left: 200px;
        right: 10px;
        padding: 0;
    }
    </style>
</head>
<body class="hold-transition skin-purple sidebar-mini">
    <div id="app">
        <el-container>
            <el-header  class="main-header" style="height:70px;">
                <nav class="navbar navbar-static-top" :class=''>
                    <!-- Logo -->
                    <a href="#" class="logo" style="text-align:center">
                        <span class="logo-lg"><img src="../img/logo.png"></span>
                    </a>
                    <div class="right-menu">
                        <span class="help"><i class="fa fa-exclamation-circle" aria-hidden="true"></i>帮助</span>
                        <el-dropdown class="avatar-container right-menu-item" trigger="click">
                            <div class="avatar-wrapper">
                                <img src="../img/user2-160x160.jpg" class="user-avatar">
                                {{username}}
                            </div>
                            <el-dropdown-menu slot="dropdown">
                                <el-dropdown-item divided>
                                    <span style="display:block;">修改密码</span>
                                </el-dropdown-item>
                                <el-dropdown-item  divided >
                                        <span style="display:block;" @click = "exit()">退出</span>
                                    </el-dropdown-item>
                            </el-dropdown-menu>
                        </el-dropdown>
                    </div>
                </nav>
            </el-header>
            <el-container>
                <el-aside width="200px">
                    <div class="custom-tree-container">
                        <div class="block">
                            <el-tree
                                    :data="menuList"
                                    show-checkbox
                                    node-key="id"
                                    :expand-on-click-node="false">
                                <span class="custom-tree-node" slot-scope="{ node, data }">
                                    <span><a :href="data.linkUrl" target="right">{{ data.name }}</a></span>
                                <span>
                                    <i class="el-icon-edit" @click="append(data)"></i>
                                    <i class="el-icon-delete" @click="remove(data)"></i>
                                </span>
                              </span>
                            </el-tree>
                            <el-dialog title="添加菜单栏" :visible.sync="dialogFormVisibleAppend">
                                <el-form :model="formData" >
                                    <el-form-item label="菜单名">
                                        <el-input v-model="formData.name"/>
                                    </el-form-item>

                                    <el-form-item label="跳转的网址" prop="linkUrl">
                                        <el-input v-model="formData.linkUrl"/>
                                    </el-form-item>
                                </el-form>
                                <div slot="footer" class="dialog-footer">
                                    <el-button @click="dialogFormVisibleAppend = false">取消</el-button>
                                    <el-button type="primary" @click="addMenus()">确定</el-button>
                                </div>
                            </el-dialog>
                        </div>
                    </div>
                    <!--<el-menu>-->
                        <!--<el-submenu v-for="menu in menuList" :index="menu.path">-->
                            <!--<template slot="title">-->
                                <!--<i class="fa" :class="menu.icon"></i>-->
                                <!--{{menu.name}}-->
                            <!--</template>-->
                            <!--<template v-for="child in menu.children">-->
                                <!--<el-menu-item :index="child.path">-->
                                    <!--<a :href="child.linkUrl" target="right">{{child.name}}</a>-->
                                <!--</el-menu-item>-->
                            <!--</template>-->
                        <!--</el-submenu>-->
                    <!--</el-menu>-->
                </el-aside>
                <el-container>
                    <iframe name="right" class="el-main" src="report_sex.html" width="100%" height="580px" frameborder="0"></iframe>
                </el-container>
            </el-container>
        </el-container>
    </div>
</body>
<!-- 引入组件库 -->
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script src="../js/vue.js"></script>
<script src="../plugins/elementui/index.js"></script>
<script src="../js/axios-0.18.0.js"></script>
<script>
    new Vue({
        el: '#app',
        data:{
            menuList:[],
            username:"",
            dialogFormVisibleAppend:false,
            formData:{},
        },
        methods:{
            load(){
                axios.post("/main/load.do").then((res)=>{
                    this.menuList = res.data.data.menus;
                    this.username = res.data.data.username;
                });
                this.formData = {};
            },
            exit(){
                location.href = "/logout.do";
            },
            append(data){
                this.dialogFormVisibleAppend = true;
                this.formData.id = data.id;
            },
            addMenus(){
                console.log(this.formData);
                axios.post("/main/append.do",this.formData).then((res)=>{
                    console.log(this.formData);
                    this.load();
                }).catch(()=>{
                    this.$message.error("添加失败")
                }).finally(()=>{
                    this.dialogFormVisibleAppend = false;
                });
            },
            remove(data){
                this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning',
                }).then(() => {
                    axios.get("/main/remove.do?id="+data.id).then((res)=>{
                        this.load();
                    }).catch(()=>{
                        this.$message.error("删除失败");
                    })
                });
            }
        },
        created(){
            this.dialogFormVisibleAppend = false;
            // this.load();
            axios.get("/user/getUserName.do").then((res)=>{
                console.log(res);
                this.username=res.data.data;
                axios.get("/menu/findMenus.do?username="+this.username).then((res)=>{
                    console.log(res);
                    this.menuList=res.data.data;
                })
            });
        }
    });
    $(function() {
            var wd = 200;
            $(".el-main").css('width', $('body').width() - wd + 'px');
    });
</script>
</html>
